package com.apexsoft.assets.base.convert;

import cn.hutool.core.util.NumberUtil;
import org.springframework.cglib.core.Converter;

public class FormatNumberConverter implements Converter {

    //精度
    private int precision = 0;

    public FormatNumberConverter() {
    }

    public FormatNumberConverter(int i) {
        this.precision = i;
    }

    @Override
    // value 源对象属性，target 目标对象属性类，context 目标对象setter方法名
    public Object convert(Object value, Class target, Object context) {
         if(value instanceof Number){
             if(value instanceof Double){
                 return NumberUtil.roundStr(value.toString(),precision);
             }else {
                 return value.toString();
             }
        }
        return value;
    }
}
